package no.hib.quiz;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MenuFragment extends Fragment{

	public void onActivityCreated(Bundle savedInstanceState) {
	    super.onActivityCreated(savedInstanceState);

	    Button btnNewQuiz =(Button)getView().findViewById(R.id.newQuizButton);
	    btnNewQuiz.setOnClickListener(new OnClickListener() {

	        @Override
	        public void onClick(View v) {

	            FragmentManager fragmentManager = getFragmentManager();
	            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

	            NewQuizFragment newQuiz = new NewQuizFragment();
	            fragmentTransaction.replace(R.id.fragment_container, newQuiz);
	            fragmentTransaction.addToBackStack(null);
	            fragmentTransaction.commit();

	        }
	    });
	    
	    Button btnStartQuiz =(Button)getView().findViewById(R.id.startQuizButton);
	    btnStartQuiz.setOnClickListener(new OnClickListener() {

	        @Override
	        public void onClick(View v) {

	            FragmentManager fragmentManager = getFragmentManager();
	            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

	            QuizListFragment quizList = new QuizListFragment();
	            fragmentTransaction.replace(R.id.fragment_container, quizList);
	            fragmentTransaction.addToBackStack(null);
	            fragmentTransaction.commit();

	        }
	    });

	}
	
	@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.menu, container, false);
 
    }

}
